package org.itboys.core.controller.web.order;

import com.wordnik.swagger.annotations.Api;
import org.itboys.core.entity.mongo.SundayOrderFailRecord;
import org.itboys.core.service.mongo.web.SundayOrderFailRecordService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2019/1/10
 * 描述：订单失败记录
 */
@Controller
@RequestMapping("/sunday/web/failRecord")
@Api(value = "failRecord", description = "订单失败记录")
public class SundayOrderFailRecordController extends BaseController {
    @Autowired
    private SundayOrderFailRecordService failRecordService;

    /**
     * 主页
     *
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/index")
    public String index(
            HttpServletRequest request,
            Model model
    ) {
        return "/sunday/failRecord/index";
    }

    /**
     * 分页查询
     *
     * @param request
     * @param response
     */
    @RequestMapping("/select")
    public void select(
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        PageResult<SundayOrderFailRecord> result = failRecordService.select(request);
        JsonPageUtils.renderJsonPage(result.getTotal(), result.getData(), response);
    }

    @RequestMapping("/handle")
    public void handle(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "recordId", required = true) Long recordId
    ) {
        failRecordService.handle(recordId);
        ResponseMessage.success();
    }


}
